package com.leapp.sk.viewdelegate.adapter.notify

import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.util.LKTimeUtil
import com.leapp.sk.R
import com.leapp.sk.bean.NotifyObjEntity

/**
 * 系统通知适配器视图托管类
 * @author  chaohaipeng  on 2018/8/15.
 */
class SystemNotifyAdapterDelegate  : BaseAdapterDelegate() {
    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }
    override fun initLayoutRes(): Int {
        return R.layout.adapter_system_notify_item
    }
    /**
     * 设置数据
     */
    fun setData(context: Context, mNotifyObjEntity: NotifyObjEntity) {
        val iv_ani_image = getView<ImageView>(R.id.iv_asni_image)
        val tv_ani_notify_type = getView<TextView>(R.id.tv_asni_notify_type)
        val tv_ani_time = getView<TextView>(R.id.tv_asni_time)
        val tv_ani_notify_content = getView<TextView>(R.id.tv_asni_notify_content)
        msgNum(context, mNotifyObjEntity)
        val formatTime = LKTimeUtil.getInstance().formatTimeA(mNotifyObjEntity.creatTime)
        tv_ani_time.text = formatTime
        tv_ani_notify_content.text=mNotifyObjEntity.content
        tv_ani_notify_type.text=mNotifyObjEntity.typeName
    }



    /**
     * 设置消息数量
     */
    private fun msgNum(context: Context, mNotifyObjEntity: NotifyObjEntity) {
        val tv_ani_notify_unread = getView<TextView>(R.id.tv_asni_notify_unread)
        if (0 != mNotifyObjEntity.unReadNum) {
            if (mNotifyObjEntity.unReadNum > 99) {
                tv_ani_notify_unread.text = "99+"

            } else {
                tv_ani_notify_unread.text = mNotifyObjEntity.unReadNum.toString()
            }
            tv_ani_notify_unread.visibility = View.VISIBLE
        } else {
            tv_ani_notify_unread.visibility = View.GONE
        }

    }
}